/* 
 *  <copyright file="TimerComponent.cs" company="Wesley Jowitt">
 *  
 *  SobrietyEngine: Copyright (c) 2011 Wesley Jowitt
 *  
 *  This software is distributed under a software license.
 *   * As of the creation time of this file, the license in use is the Microsoft Permissive License (Ms-PL) 
 *    * The license can be viewed at:
 *     * License.Txt in the root folder of this project
 *      * http://sobrietyengine.codeplex.com/license
 *       * http://www.microsoft.com/opensource/licenses.mspx
 *       
 *  </copyright>
 *   */

using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework;

using SobrietyEngine.Common;
using SobrietyEngine.Events;
using SobrietyEngine.Processes.Events;

namespace SobrietyEngine.Components.Timer
{
    public class TimerComponent : BaseComponent, SobrietyEngine.Components.IComponent
    {
        float timer = -1;
        float timeElapsed = 0;

        public float TimeElapsed
        {
            get { return timeElapsed; }
        }


        public TimerComponent()
            : base()
        {           
        }

        override public void Set(Parameters parms)
        {
            if (parms.Params.ContainsKey("TimeLimit"))
            {
                timer = (float)parms["TimeLimit"];
            }
        }

        public override Boolean InitComponent()
        {
            return base.InitComponent();
        }

        public new void Update(GameTime ElapsedTime)
        {
            timeElapsed += ElapsedTime.ElapsedGameTime.Milliseconds;

            if (timeElapsed >= timer && timer > 0)
            {
                ParentActor.EventRouter.RaiseEvent(this, new TimerCompleted());
            }
        }


    }
}